package com.martin.ads.vrlib.textures;

import android.opengl.GLES20;

import com.martin.ads.vrlib.utils.TextureUtils;

import java.nio.ByteBuffer;


/**
 * Created by Ads on 2017/1/31.
 */

public class RGBTexture {
    private int imageTextureId;
    private int imageSize[];

    public RGBTexture() {
        imageSize = new int[2];
    }


    public RGBTexture loadRGB(byte[] rgbs, int width, int height) {
//        IntBuffer buffer = IntBuffer.allocate(width * height).put(rgbs);
        ByteBuffer buffer = ByteBuffer.allocate(rgbs.length).put(rgbs);
        buffer.position(0);
        imageSize[0] = width;
        imageSize[1] = height;
        imageTextureId = TextureUtils.loadTexture(buffer, width, height, imageTextureId);
        return this;
    }

    public int getRGBTextureId() {
        return imageTextureId;
    }

    public int getImageWidth() {
        return imageSize[0];
    }

    public int getImageHeight() {
        return imageSize[1];
    }

    public void destroy() {
        GLES20.glDeleteTextures(1, new int[]{imageTextureId}, 0);
    }
}
